home *** CD-ROM | disk | FTP | other *** search
Text File | 1997-06-28 | 982 b | 70 lines | [TEXT/CWIE] |
- // Postponer.cp
-
- #ifndef Postponer_h
- #include "Postponer.h"
- #endif
- #ifndef Method_h
- #include "Method.h"
- #endif
-
- Postponer::Postponer( const Method& theMethod )
- : link( this ),
- perform( theMethod )
- {
- TheList();
- }
-
- Postponer::~Postponer()
- {
- }
-
- ListOf< Postponer >& Postponer::TheList()
- {
- static ListOf< Postponer > list;
- return list;
- }
-
- void Postponer::Schedule()
- {
- Assert( !Pending() );
- TheList().Add( link, afterEnd );
- }
-
- void Postponer::Cancel()
- {
- Assert( Pending() );
- TheList().Remove( link );
- }
-
- void Postponer::Flush()
- {
- if ( Pending() )
- {
- Cancel();
- this->perform();
- }
- }
-
- void Postponer::Execute( Tick stop )
- {
- ListOf< Postponer >& list( TheList() );
-
- while ( !list.IsEmpty() )
- {
- Postponer *p = list.First()->Target();
- list.Remove( p->link );
- p->perform();
-
- if ( Tick::Now() >= stop )
- break;
- }
- }
-
- bool Postponer::CanSleep()
- {
- return TheList().IsEmpty();
- }
-
- #include "ListLink.cp"
- #include "ListOf.cp"
-